package com.efast.dmom.mgmt.controller.les;

import java.util.List;
import java.util.Map;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.dao.les.TwInvSkuLoctlDao;
import com.efast.dmom.mgmt.entity.les.TwAdjDetails;
import com.efast.dmom.mgmt.entity.les.TwInvSkuLoctl;
import com.efast.dmom.mgmt.entity.master.TmBasDloc;
import com.efast.dmom.mgmt.entity.master.TmBasLoc;
import com.efast.dmom.mgmt.service.les.TwAdjDetailsService;
import com.efast.dmom.mgmt.utils.Assist;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @描述
 * @创建人 ChenLiPeng
 * @创建时间 2018年4月17日下午3:57:32
 * @修改人
 * @修改时间 2018年4月17日下午3:57:32
 * @since JDK 1.8
 */
@Controller
@RequestMapping(value = "/twAdjDetail")
@Api(description = "物流执行管理-->库存调整-->库存调整单(明细)")
public class TwAdjDetailController {

	@Autowired
	private TwAdjDetailsService twAdjDetailsService;
	/**
	 * 库存表TW_INV_SKU_LOC_T_L
	 */
	@Autowired
	private  TwInvSkuLoctlDao twInvSkuLoctlDao;

	/**
	 * 
	 * @描述  新增库存调整单--明细
	 * @方法名 add
	 * @param twAdjDetails
	 * @return
	 * @返回类型 ResultBean
	 * @创建人 ChenLiPeng
	 * @创建时间 2018年4月17日下午7:49:41
	 * @修改人
	 * @修改时间 2018年4月17日下午7:49:41
	 */
	@ApiOperation(value = "【新增库存调整单--明细】", notes = "请求参数：")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public @ResponseBody ResultBean add(@RequestBody TwAdjDetails twAdjDetails) {
		ResultBean result = new ResultBean(true, "'");
		twAdjDetailsService.insertNonEmptyTwAdjDetails(twAdjDetails);
		return result;
	}

	/**
	 * @Title: confirmPicking
	 * @Description:明细按行关闭
	 * @param twAdjHeader
	 * @param @return
	 *            参数
	 * @return ResultBean 返回类型
	 */
	@ApiOperation(value = "【按行关闭】", notes = "请求参数：只需要传递明细的id就可以")
	@RequestMapping(value = "/close", method = RequestMethod.POST)
	public @ResponseBody ResultBean close(@RequestBody TwAdjDetails twAdjDetails) {
		ResultBean result = new ResultBean(true, "'");
		twAdjDetails.setLineStatus("3"); // 单据状态 :0新单,1发布,2完成,3关闭,4部分调整
		twAdjDetailsService.updateNonEmptyTwAdjDetailsById(twAdjDetails);
		return result;
	}

	/**
	 *
	 * @Title: confirmPicking @Description:根据仓库查询库区 @param @param
	 *         twAdjHeader @param @return 参数 @return ResultBean 返回类型 @throws
	 */
	@ApiOperation(value = "【根据仓库查询库区】", notes = "请求参数： {\"wh\":\"xxx\"}")
	@RequestMapping(value = "/queryDloc", method = RequestMethod.POST)
	public @ResponseBody ResultBean queryDloc(@RequestBody Map<Object, Object> map) {
		ResultBean result = new ResultBean(true, "'");
		List<TmBasDloc>  listTmBasDloc= twAdjDetailsService.queryDlocByWh((int) map.get("wh"));
		result.setObject(listTmBasDloc);
		return result;
	}

	/**
	 * @Title: confirmPicking
	 * @Description:根据库区查询库位
	 * @param @param
	 *            twAdjHeader
	 * @param @return
	 *            参数
	 * @return ResultBean 返回类型
	 */
	@ApiOperation(value = "【根据库区查询库位】", notes = "请求参数： {\"dLoc\":\"xxx\"}")
	@RequestMapping(value = "/queryLoc", method = RequestMethod.POST)
	public @ResponseBody ResultBean queryLoc(@RequestBody Map<Object, Object> map) {
		ResultBean result = new ResultBean(true, "'");
		List<TmBasLoc> listTmBasLoc= twAdjDetailsService.queryLocByDloc((int) map.get("dLoc"));
		result.setObject(listTmBasLoc);
		return result;
	}
	
	/**
	 * @Title: confirmPicking
	 * @Description:根据库位查询内部跟踪号
	 * @param @param
	 *            twAdjHeader
	 * @param @return
	 *            参数
	 * @return ResultBean 返回类型
	 */
	@ApiOperation(value = "【根据库位查询内部跟踪号】", notes = "请求参数： {\"serialNo\":\"xxx\"}")
	@RequestMapping(value = "/queryInbSerialNo", method = RequestMethod.POST)
	public @ResponseBody ResultBean queryInbSerialNo(@RequestBody Map<Object, Object> map) {
		ResultBean result = new ResultBean(true, "'");
		Assist assist = new Assist();
		assist.setRequires(Assist.andEq("loc_no", map.get("serialNo")));
		List<TwInvSkuLoctl> twInvSkuLoctls = twInvSkuLoctlDao.selectTwInvSkuLoctl(assist);
		result.setObject(twInvSkuLoctls);
		return result;
	}
}
